package codegen

import groovy.swing.j2d.*
import java.awt.*
import javax.swing.*
import groovy.swing.SwingBuilder
import java.awt.BorderLayout as BL
import codegen.graphnetwork.ui.*
import codegen.graphnetwork.model.*
//import codegen.nbvisual.*
import codegen.jung.*

import org.netbeans.api.visual.vmd.VMDGraphScene
//import codegen.nbvisual.NBGraphTest
import codegen.nbvisual.visual.*
import codegen.ui.nbvisual.visual.CodeGenGraphManager
import codegen.glsl.ui.PreviewPanel
jPanel = null
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
/*
// Use atomix's TestGraph 
gd = new GraphDisplayer()
//graph.contructGraph()
 */
// Use JUNG
/*
graphTest = new GraphTest();
 */

// Use Netbean visual library

graphTest = new CodeGenGraphManager();
graphTest.createScene();
/**/
def getTestGraph(){
    // add a var Sum
    // add 2 parameter , uniform / atrribute
    // input the parameters into "+" operation -> Sum
    // check the syntax result
    // check the display result
    
}
def createIcon(String path){
    return swing.imageIcon(resource:"../images/"+path,class:TestGraphDisplayer.class)
}
swing = new SwingBuilder();
swing.edt {
    jFrame = frame( title: 'Graph', size: screenSize,
        locationRelativeTo: null, show: true ,defaultCloseOperation: JFrame.EXIT_ON_CLOSE){
        
        borderLayout()
        
        menuBar() {
            menu(text: "File", mnemonic: 'F') {
                menuItem(text: "Open", mnemonic: 'L', actionPerformed: { })
                menuItem(text: "Save", mnemonic: 'L', actionPerformed: { })
                separator()
                menuItem(text: "Exit", mnemonic: 'X', actionPerformed: {dispose() })
            }
            menu(text: "Edit", mnemonic: 'C') {

            
            }
        
            menu(text: "View", mnemonic: 'C') {
                menuItem(text: "Spectrum Gradient", mnemonic: 'L', actionPerformed: {d.show() })
            
            }

            menu(text: "Window", mnemonic: 'C') {

            
            }
            menu(text: "Help", mnemonic: 'C') {

            
            }
        }
        toolBar(constraints:BL.NORTH){
        
            button( toolTipText:"New",icon:createIcon("ToolbarIcons/24/New.png"))
            button( toolTipText:"Open",icon:createIcon("ToolbarIcons/24/Open.png"))
            button( toolTipText:"Save",icon:createIcon("ToolbarIcons/24/Save.png"))
            separator(orientation:SwingConstants.VERTICAL)
            button( toolTipText:"Copy",icon:createIcon("ToolbarIcons/24/Copy.png"))
            button( toolTipText:"Cut",icon:createIcon("ToolbarIcons/24/Cut.png"))
            button( toolTipText:"Paste",icon:createIcon("ToolbarIcons/24/Paste.png"))
            button( toolTipText:"Delete",icon:createIcon("ToolbarIcons/24/Delete.png"))
            separator(orientation:SwingConstants.VERTICAL)
            toggleButton( toolTipText:"Select",icon:createIcon("ToolbarIcons/24/Select.png"))
            toggleButton( toolTipText:"AddNode",icon:createIcon("ToolbarIcons/24/AddNode.png"),actionPerformed:{
                    if (graphTest.isAddingNodeMode()){
                        graphTest.setAddingNodeMode(false);
                    } else {
                        graphTest.setAddingNodeMode(true);
                    }
                });
            
            separator(orientation:SwingConstants.VERTICAL)
            toggleButton( toolTipText:"Play",icon:createIcon("ToolbarIcons/24/Play.png"))
            button( toolTipText:"Connect",icon:createIcon("ToolbarIcons/24/Connect.png"))
            button( toolTipText:"Disconnect",icon:createIcon("ToolbarIcons/24/Disconnect.png"))
            
        }
        
        jPanel=panel(constraints:BL.CENTER,id:"gp"){
            borderLayout()
            scrollPane(constraints:BL.CENTER){
                //widget(graphTest.getView())
                widget(graphTest.view)
            }
            /*
            panel(constraints:BL.CENTER,new GraphZoomScrollPane(vv)){
            borderLayout()
            panel(constraints:BL.CENTER,vv)
            }
             */
        }
        panel(constraints:BL.WEST){
            panel(constraints:"up"){
                borderLayout()
                panel(constraints:BL.SOUTH,background:Color.white,preferredSize:[220,200]){
                    borderLayout()
                    label(text:"Navigator",constraints:BL.NORTH)
                    //widget(graphTest.getBirdEyeView(),constraints:BL.CENTER)
                    widget(graphTest.birdEyeView,constraints:BL.CENTER)
                    
                }
                tabbedPane(constraints:BL.CENTER){
                    panel(title:"Project"){
                        borderLayout()
                        scrollPane (constraints:BL.CENTER){
                            tree() 
                        }  
                    }
                    panel(title:"Palette"){
   
                        borderLayout()
                        button(constraints:BL.NORTH,text:"Add")
                        scrollPane (constraints:BL.CENTER){
                            panel(constraints:BL.CENTER){
                                gridLayout(cols:1,rows:5)
                                (1..5).each{
                                    button(text:"Node"+it)
                                }
                            }  
                        }
                    }
                    panel(title:"Structure"){
                        borderLayout()
                        scrollPane (constraints:BL.CENTER){
                            tree() 
                        }
                    }
                }
                
            }

        } 
        panel(constraints:BL.SOUTH){
            borderLayout()
            tabbedPane(){
                scrollPane (title:"Result"){
                    textPane(text:"""
<html>
    <body>
    </body>
</html>
""")
                }
                scrollPane (title:"Log"){
                    textArea(text:"Log")
                }
            }
        }
        panel(constraints:BL.EAST){
            borderLayout()
            button(constraints:BL.NORTH,text:"Preview")
            panel(constraints:BL.CENTER,new PreviewPanel(),preferredSize:[120,120])
            panel(constraints:BL.SOUTH){
                gridLayout(cols:2,rows:5)
                
                (1..5).each{
                    label(text:"Properties"+it)
                    if (it%2==0){
                        textField(text:"Node")
                    } else {
                        slider(preferredSize:[120,20])
                    }
                }
            }
        }
    }
}

/*
public def graphChange(){

jPanel.graphicsOperation= gd.display(jPanel,graph)
}

jPanel.graphicsOperation= gd.display(jPanel,graph)
gd.addGraphChangeListener(this)
 */
